package com.imooc.controller;

import com.imooc.bo.ShopCartBo;
import com.imooc.service.ItemsService;
import com.imooc.utils.IMOOCJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author wangke
 * @version 1.0.0
 * @Description  购物车相关controller
 * @createTime 2021年08月01日 11:34:00
 */

@RestController
@RequestMapping("/shopcart")
@Api(value = "购物车功能相关接口",tags = {"购物车相关接口"})
public class ShopCartController {
    private ItemsService itemsService;

    @PostMapping("/add")
    @ApiOperation(value = "购物车数据保存",notes ="用户登录情况下的购物车数据同步redis")
    public IMOOCJSONResult add(@RequestParam String userId, @RequestBody ShopCartBo shopCartBo, HttpServletRequest request, HttpServletResponse response){
          if(StringUtils.isBlank(userId)){
              IMOOCJSONResult.errorMsg("用户ID不能为空");
          }
       //Todo 校验用户token 信息，存储用户购物车信息到reidis
      return   IMOOCJSONResult.ok();

    }

    //处理购物车删除商品
    @PostMapping("/del")
    @ApiOperation(value = "购物车商品移除",notes = "用户登录情况下移除购物车商品",httpMethod = "POST")
    public IMOOCJSONResult delShopCart(@RequestParam String userId,@RequestParam String itemSpecId){
        if(StringUtils.isBlank(userId)&&StringUtils.isBlank(itemSpecId)){
            return IMOOCJSONResult.errorMsg("参数不能为空");
        }
       //TODO 判断用户是否登录，在登陆情况下移除redis 中的相关购物车中的商品信息

        return IMOOCJSONResult.ok();
    }

}
